package no.ntnu.fp.model;




public class Time {
	private int hours;
	private int minutes;
	
	public Time() {
		hours = 0;
		minutes = 0;
	}
	
	public Time(int hours, int minutes) {
		this.hours = hours;
		this.minutes = minutes;
	}
	
	public Time(String time) {
		try {
			this.hours = Integer.parseInt(time.substring(0,2));
			this.minutes = Integer.parseInt(time.substring(3,5));
		}
		catch (NumberFormatException nfe) {
		}
	}
	
	public int getHours() {
		return hours;
	}
	
	public int getMinutes() {
		return minutes;
	}
	
	public  void setHours(int hours) {
		this.hours = hours;
	}
	
	public void setMinutes(int minutes) {
		this.minutes = minutes;
	}
	
	public String toString() {
		String h, m;
		if (hours < 10) {
			h = "0"+hours;
		}
		else {
			h = String.valueOf(hours);
		}
		if (minutes < 10) {
			m = "0"+minutes;
		}
		else {
			m = String.valueOf(minutes);
		}
		return h+":"+m;
	}
	
	/**
	 * 
	 * 
	 * @param time
	 * @return 0 if equal, 1 if time > this, -1 if time < this
	 */
	public int compareTo(Time time) {
		if (this.hours < time.getHours()) {
			return 1;
		}
		else if (this.hours > time.getHours()) {
			return -1;
		}
		else {
			if (this.minutes < time.getMinutes()) {
				return 1;
			}
			else if (this.minutes > time.getMinutes()) {
				return -1;
			}
		}
		return 0;
	}
}